package com.igoal.service.dwr;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.igoal.dto.UserDTO;
import com.igoal.entity.ComponentEnum;
import com.igoal.service.LikeService;

@Service("likeServiceDWR")
public class LikeServiceDWRImpl extends BaseDWRService implements LikeServiceDWR {

	private LikeService likeService;

	@Autowired
	public void setLikeService(LikeService likeService) {
		this.likeService = likeService;
	}

	public int like(String component, Long componentId) {
		String username = getUserInSession();
		return likeService.likeComponent(username, component, componentId);
	}

	public int unlike(String component, Long componentId) {
		String username = getUserInSession();
		return likeService.unlikeComponent(username, component, componentId);
	}

	public List<String> getRandomLikeList(Long userId, Long componentId, String component) {
		List<UserDTO> users = likeService.getRandomLikeUsers(userId,
				ComponentEnum.valueOf(component), componentId);
		List<String> likes = new ArrayList<String>();
		if(users != null){
			for (UserDTO u : users) {
				likes.add(u.getUsername());
			}
		}
		return likes;
	}

	public int count(String component, Long componentId) {
		int count = likeService.likeCount(ComponentEnum.valueOf(component), componentId);
		return count;
	}

}
